package com.cxrj.zhsq.housePropertyManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.housePropertyManage.entity.PropertyHouse;
import com.cxrj.zhsq.housePropertyManage.service.HousePropertyService;

@RestController
public class HousePropertyController {
	
	@Resource
	private HousePropertyService housePropertyService;
	
	/**
	 * 添加房屋
	 * @param propertyHouse
	 * @param request
	 * @return
	 */
	@RequestMapping("insertHouseProperty")
	public Map<String, Object> insertHouseProperty(PropertyHouse propertyHouse,String[] houses,HttpServletRequest request){
		return housePropertyService.insertHouseProperty(propertyHouse,houses,request);
	}
	
	/**
	 * 查询所有
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectHouseList")
	public Map<String, Object> selectHouseList(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectHouseList(request,response);
	}
	
	/**
	 * 根据Id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("selectHouseById")
	public Map<String, Object> selectHouseById(String id){
		return housePropertyService.selectHouseById(id);
	}
	
	/**
	 * 更新
	 * @param propertyHouse
	 * @return
	 */
	@RequestMapping("updateHouseProperty")
	public Map<String, Object> updateHouseProperty(PropertyHouse propertyHouse){
		return housePropertyService.updateHouseProperty(propertyHouse);
	}
	
	/**
	 * 单个添加
	 * @param propertyHouse
	 * @return
	 */
	@RequestMapping("insertHousePropertyOne")
	public Map<String, Object> insertHousePropertyOne(HttpServletRequest request,PropertyHouse propertyHouse){
		return housePropertyService.insertHousePropertyOne(request,propertyHouse);
	}
	
	/**
	 * 删除
	 * @param propertyHouse
	 * @return
	 */
	@RequestMapping("delHouse")
	public Map<String, Object> deleteHouse(PropertyHouse propertyHouse){
		return housePropertyService.deleteHouse(propertyHouse);
	}
	
	/**
	 * 查询期数
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectNumberPeriods")
	public Map<String, Object> selectNumberPeriods(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectNumberPeriods(request,response);
	}
	
	/**
	 * 查询楼栋
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectBuilding")
	public Map<String, Object> selectBuilding(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectBuilding(request,response);
	}
	
	/**
	 * 查询单元
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectUnit")
	public Map<String, Object> selectUnit(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectUnit(request,response);
	}
	
	/**
	 * 房间号
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectDoorCard")
	public Map<String, Object> selectDoorCard(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectDoorCard(request,response);
	}
	
	@RequestMapping("checkingBuilding")
	public Map<String, Object> checkingBuilding(HttpServletRequest request,String numberPeriods,String building){
		return housePropertyService.selectCheckingBuilding(request,numberPeriods,building);
	}
	
	@RequestMapping("checkingDoorCard")
	public Map<String, Object> checkingDoorCard(HttpServletRequest request,String numberPeriods,String building,String unit,String doorCard){
		return housePropertyService.selectCheckingDoorCard(request,numberPeriods,building,unit,doorCard);
	}
	
	/**
	 * 查询房屋信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectHouseData")
	public Map<String, Object> selectHouseData(HttpServletRequest request,HttpServletResponse response){
		return housePropertyService.selectHouseData(request,response);
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("deleteByIds")
	public Map<String, Object > deleteByIds(@RequestParam("ids[]") String[] ids){
		return housePropertyService.deleteByIds(ids);
	}

	/**
	 * 查询缴费信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectHousePay", method = RequestMethod.POST)
	public Map<String, Object> selectHousePay(String id, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = housePropertyService.selectByPayDetail(id);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	/**
	 * 房屋装修信息修改
	 * @param house
	 * @param request
	 * @return
	 */
	@RequestMapping("updateHouseState")
	public Map<String, Object> updateHouseState(PropertyHouse house,HttpServletRequest request){
		return housePropertyService.updateHouseState(house,request);
	}
}
